package com.woniu.venue.controller;


import cn.hutool.core.bean.BeanUtil;
import com.github.pagehelper.PageInfo;
import com.woniu.model.Result;
import com.woniu.venue.dto.venueClassroom.VenueClassroomDto;
import com.woniu.venue.form.venueClassroom.AddVenueClassroomForm;
import com.woniu.venue.form.venueClassroom.LoadVenueClassroomForm;
import com.woniu.venue.form.venueClassroom.UpdateVenueClassroomForm;
import com.woniu.venue.model.VenueClassroom;
import com.woniu.venue.param.venueClassroom.AddVenueClassroomParam;
import com.woniu.venue.param.venueClassroom.LoadVenueClassroomParam;
import com.woniu.venue.param.venueClassroom.UpdateVenueClassroomParam;
import com.woniu.venue.service.VenueClassroomService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Set;

/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author 杜岷芫
 * @since 2024年07月12日
 */

@Api(tags = "场馆教室信息")
@RestController
@RequestMapping("/venueClassroom")
public class VenueClassroomController {

    @Autowired
    private VenueClassroomService venueClassroomService;

    /**
     * 增
     */
    @ApiOperation("新增教室")
    @PostMapping("/add")
    public Result add(@RequestBody AddVenueClassroomForm form) {
        VenueClassroomDto venueClassroomDto= venueClassroomService.add(BeanUtil.toBean(form, AddVenueClassroomParam.class));
        return Result.getResult().setMsg("成功").setData(venueClassroomDto);
    }

    /**
     * 改状态（假删除）
     */
    @ApiOperation("修改教室状态")
    @GetMapping("/changeState/classroomId/state")
    public Result changeState(@PathVariable(value = "classroomId") Integer classroomId,@PathVariable(value = "state") Integer state) {
        VenueClassroomDto venueClassroomDto = venueClassroomService.changeState(classroomId, state);
        return Result.getResult().setMsg("成功").setData(venueClassroomDto);
    }

    /**
     * 修改
     */
    @ApiOperation("更新教室信息")
    @PostMapping("/updateVenueClassroom")
    public Result updateVenueClassroom(@RequestBody UpdateVenueClassroomForm form) {
        VenueClassroomDto venueClassroomDto = venueClassroomService.updateVenueClassroom(BeanUtil.toBean(form, UpdateVenueClassroomParam.class));
        return Result.getResult().setMsg("成功").setData(venueClassroomDto);
    }

    @ApiOperation("加载所有教室")
    @PostMapping("/load")
    public Result load(@RequestBody LoadVenueClassroomForm form) {
        PageInfo<VenueClassroomDto> venueClassroomDtos = venueClassroomService.load(BeanUtil.toBean(form, LoadVenueClassroomParam.class));
        return Result.getResult().setMsg("成功").setData(venueClassroomDtos);
    }

    @ApiOperation("加载所有教室for addClass")
    @GetMapping("/loadAll/{venueId}/{classType}")
    public Result loadAll(@PathVariable("venueId") Integer venueId,@PathVariable("classType") Integer classType) {
        List<VenueClassroom> venueClassrooms = venueClassroomService.loadAll(venueId,classType);
        return Result.getResult().setMsg("成功").setData(venueClassrooms);
    }


    @ApiOperation("根据id查询教室")
    @GetMapping("/loadVenueRoom/{id}")
    public Result loadVenueRoom(@PathVariable("id") Integer id){
        VenueClassroom byId = venueClassroomService.getById(id);
        return Result.getResult().setData(byId).setMsg("成功");
    }

    @ApiOperation("根据id查询教室")
    @PostMapping("/loadVenueRooms")
    public Result loadVenueRooms(@RequestBody Set<Integer> ids){
        List<VenueClassroomDto> byIds = venueClassroomService.getByIds(ids);
        return Result.getResult().setData(byIds).setMsg("成功");
    }
}

